package org.example.DAO;

import org.example.Model.student;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import java.beans.BeanProperty;
import java.util.List;
@Repository(value = "studentDAOimpl")
public class studentDAOimpl extends AbstractstudentDAO{
    @Override
    public void insertstu(student stu) {
        super.insertstu(stu);
        String INSERT_STUDENT="INSERT INTO student(Sno,Sname,Ssex,Sage,Sdept)VALUES(?,?,?,?,?)";
         Object[] args={stu.getSno(),stu.getSname(),stu.getSsex(),stu.getSage(),stu.getSdept()};
         jdbcTemplate.update(INSERT_STUDENT,args);
    }

    @Override
    public void modifystu(student stu) {
        super.modifystu(stu);
        String MODIFY_STUDENT="UPDATE student SET Sno=?,Sname=?,Ssex=?,Sage=?,Sdept=?";
        Object[] args={stu.getSno(),stu.getSname(),stu.getSsex(),stu.getSage(),stu.getSdept()};
        jdbcTemplate.update(MODIFY_STUDENT,args);

    }

    @Override
    public List<student> queryAll() {
        String QUERY_ALL_STUDENT="select * from student";
        RowMapper<student> rowMapper=new BeanPropertyRowMapper< >(student.class);
        students=jdbcTemplate.query(QUERY_ALL_STUDENT,rowMapper);
        return students;

    }
}
